package gui.frames;

import gui.actions.PlayBackAction;
import gui.models.PlayModel;
import gui.panels.CopyrightPanel;
import gui.panels.CopyrightPanel.ButtonTypeEnum;
import gui.panels.play.PlayButtonsPanel;
import gui.panels.play.PlayQuestionsPanel;
import gui.utils.ComponentUtils;

import java.awt.BorderLayout;
import java.util.Observable;
import java.util.Observer;

import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class PlayFrame extends JFrame implements Observer {

    private static final long serialVersionUID = 1L;
    private final PlayModel model;
	private final PlayQuestionsPanel playQuestionsPanel;
	private final PlayButtonsPanel playButtonsPanel;

    public PlayFrame() {
    	model = new PlayModel(this);    	
    	model.addObserver(this);
    	playQuestionsPanel = new PlayQuestionsPanel(model);
    	playButtonsPanel = new PlayButtonsPanel(model);
    	buildFrame();
    }

	private void buildFrame() {
		JPanel mainPanel = new JPanel();
    	mainPanel.setLayout(new BorderLayout());
		mainPanel.add(playButtonsPanel, BorderLayout.SOUTH);
		mainPanel.add(playQuestionsPanel, BorderLayout.CENTER);    
    	
    	setLayout(new BorderLayout());
    	add(mainPanel, BorderLayout.CENTER);
    	CopyrightPanel copyrightPanel = new CopyrightPanel(ButtonTypeEnum.BACK_BUTTON, new PlayBackAction(playButtonsPanel,model));
    	copyrightPanel.setBorder(BorderFactory.createEmptyBorder(0,0,0,0));
		add(copyrightPanel, BorderLayout.SOUTH); 
    	
        setResizable(false);
        setSize(700,665);
        setLocationRelativeTo(null);
        setTitle("Play");
        ComponentUtils.installWindowClosingListener(this);
	}

	@Override
	public void update(Observable o, Object arg) {
		playButtonsPanel.update();
		playQuestionsPanel.update();
	}
    
}
